package model;

import java.sql.*;
import java.util.ArrayList;

import connection.DbConnection;
import bean.Poll;
import bean.PollUser;


public class UserlistImpl {
	
	private static PreparedStatement st;
	private static Connection conn;
	private static ResultSet rs;
		
	public static ArrayList<PollUser> showUser(String Pollid){
		ArrayList<PollUser> f = new ArrayList<PollUser>();		
		try{
			rs = null;
			conn = new DbConnection().getConn();	    	
			st = conn.prepareStatement("Select username from User_poll where pollid ='"+Pollid+"' ");
			rs=st.executeQuery();				
	    	while(rs.next()){
	    		PollUser pb = new PollUser();
	    		pb.setUsername(rs.getString(1));	     		
	    		f.add(pb);		
	    	}
		}catch(Exception e){
			e.printStackTrace();
		}
		return f;				
	}
	public static Boolean changeStatus(String Pollid, String Username) throws SQLException{
		try{
			rs = null;
			conn = new DbConnection().getConn();	    	
			st = conn.prepareStatement("Select answer.UsernameorDeviceID from answer , question, poll_question where answer.questionid = question.questionid and poll_question.questionid = question.questionid and poll_question.pollid ='"+Pollid+"' and answer.UsernameorDeviceID ='"+Username+"'and question.status = 1");
			rs=st.executeQuery();	
			
		}
		catch(Exception e){
		e.printStackTrace();
	}
		if(rs.next()){
    		return true;
    	}
    	else{
    		return false;
    	}
	}
}